<template>
  <div class="main-content">
    <p class="maintitle">审核订单详情</p>

    <el-form
      :model="getListData"
      label-position="left"
      :inline="true"
      ref="sForm"
    >
      <el-row style="margin-right: 20px">
        <el-form-item label="花型编号" prop="no">
          <el-input
            v-model="getListData.no"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="花型系列" prop="series">
          <el-input
            v-model="getListData.series"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="花型单位" prop="unit">
          <el-input
            v-model="getListData.unit"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="物料库存" prop="stock">
          <el-input
            v-model="getListData.stock"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="封板区域" prop="region">
          <el-input
            v-model="getListData.region"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
         <el-form-item label="封板国家" prop="country">
          <el-input
            v-model="getListData.country"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item> -->
         <el-form-item label="终客编号" prop="fnum">
          <el-input
            v-model="getListData.cstmr_name"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="下单数量" prop="num1">
          <el-input
            v-model.number="getListData.num1"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
         <el-form-item>
          <span>-></span>
        </el-form-item>
        <el-form-item label="下单数量" prop="num2">
          <el-input
            v-model.number="getListData.num2"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item> -->
        <!-- <el-form-item label="封板时间" prop="created">
          <el-date-picker
            v-model="getListData.created"
            type="daterange"
            range-separator="->"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="交期时间" prop="delivery_date">
          <el-date-picker
            v-model="getListData.delivery_date"
            type="daterange"
            range-separator="->"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-button
          size="medium"
          class="filter-item"
          type="primary"
          @click="getList"
          >查询</el-button
        >
        <el-button size="medium" class="filter-item" @click="resetSearch"
          >重置</el-button
        >
      </el-row>
    </el-form>

    <el-table
      :data="tableData"
      border
    >
      <el-table-column type="selection" width="50"></el-table-column>
      <el-table-column prop="no" label="花型编号" width="180" align="center">
      </el-table-column>
      <el-table-column
        prop="series"
        label="花型系列"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="unit" label="花型单位" width="150" align="center">
      </el-table-column>
      <el-table-column
        prop="num"
        label="下单数量"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="stock"
        label="物料库存"
        width="150"
        align="center"
      >
      </el-table-column>
      <!-- <el-table-column
        prop="region"
        label="封板区域"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="country"
        label="封板国家"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="sealing_time"
        label="封板时间"
        width="150"
        align="center"
      >
      </el-table-column> -->
      <el-table-column
        prop="fnum"
        label="终客编号"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="delivery_date"
        label="要求交期"
        width="150"
        align="center"
        :formatter="formatterTime"
      >
      </el-table-column>
      <el-table-column
        prop="remark"
        label="备注"
        width="150"
        align="center"
      >
      </el-table-column>
      <!-- </el-table-column> -->
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="handleEdit(row)"
            >编辑</el-button
          >
          <el-popconfirm
            confirm-button-text="确认"
            cancel-button-text="取消"
            title="确认删除当前花型？"
            @confirm="deleteRow(row.oid, row.pid)"
            style="margin-left: 10px"
          >
            <el-button size="mini" type="text" slot="reference"
              >删除该花型</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      style="text-align: right"
      v-show="totalPage > 0"
      :total="totalPage"
      :page.sync="getListData.pageNo"
      :limit.sync="getListData.pageSize"
      @pagination="getList"
    ></pagination>

     <el-dialog title="编辑" :visible.sync="dialogVisible" width="60%">
      <el-form
        :model="form"
        ref="acForm"
        label-position="left"
        label-width="150px"
        :inline="true"
      >
        <el-row>
          <el-form-item label="下单数量" prop="num">
            <el-input clearable v-model="form.num" type="number"></el-input>
          </el-form-item>
          <el-form-item label="要求交期" prop="delivery_date">
             <el-date-picker
              v-model="form.delivery_date"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-row>


         <el-form-item label="备注" prop="remark">
            <el-input
            type="textarea"
            placeholder="请输入内容"
            v-model="form.remark">
          </el-input>
          </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="dialogStatus === 'create' ? updateData('') : updateData()"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from "element-ui";
import { orderInfo, orderPatDelete,editOrder } from "@/app/api/order";
import { mapState } from "vuex";
import Pagination from "@/app/components/Pagination";

export default {
  components: {
    Pagination,
  },
  name: "Persinal",
  data() {
    return {
      importVisible: false,
      loading: false,
      tableData: [],
      totalPage: 1,
      listLoading: true,
      getListData: {
        oid: 0,
        pageNo: 1,
        pageSize: 10,
      },
      dialogVisible: false,
      form: {},
      dialogStatus: "", //编辑或新增
      textMap: {
        update: "编辑",
        create: "新增",
      },
      baseurl: api_url,
    };
  },
  computed: {
    ...mapState("user", ["session", "account"]),
  },
  created() {
    this.getListData.oid = this.$route.params.oid;
    this.getList();
  },
  methods: {
    formatterTime(row, column) {
      let data = row[column.property];
      return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data);
    },
    resetSearch() {
      this.$refs["sForm"].resetFields();
      this.getListData.delivery_date = "";
      this.getList();
    },
    getList() {
      orderInfo(this.getListData)
        .then((res) => {
          this.tableData = res.data.ret;
          this.totalPage = res.data.count;
          this.listLoading = false;
        })
        .catch((error) => {
          console.log("studentSourceList error", error);
        });
    },
    deleteRow(oid,pid) {
      orderPatDelete({ oid,pid })
        .then((res) => {
          if (res.code == "00000") {
            Message({
              message: "删除成功",
              type: "success",
              duration: 5 * 1000,
            });
            this.getList();
          }
        })
        .catch((error) => {
          console.log("save error", error);
        });
    },
    handleCreate() {
      this.getProperty();
      this.dialogStatus = "create";
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs["acForm"].clearValidate();
      });
    },
    updateData(id) {
      this.$refs["acForm"].validate((valid) => {
        if (valid) {
          if (id) {
            this.form.id = id;
          }
          editOrder(this.form)
            .then((res) => {
              if (res.code == "00000") {
                Message({
                  message: "操作成功",
                  type: "success",
                  duration: 2 * 1000,
                });
                this.getList();
                this.dialogVisible = false;
              }
            })
            .catch((error) => {
              console.log("editOrder error", error);
            });
        } else {
          return false;
        }
      });
    },
    handleEdit(row) {
      this.form = Object.assign({}, this.form, row);
      console.log(this.form);
      this.dialogStatus = "update";
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs["acForm"].clearValidate();
      });
    },
  },
};
</script>

<style>
.main-content{
  width: 97%;
  height: 840px;
  margin: 1% auto;
  border-radius: 10px;
  box-shadow: 7px 7px 10px 0px rgba(0, 0, 0, 0.25);
  background-color: #fbfbfb;
  padding: 0px;
  position: relative;
}
.maintitle{
  font-family: Roboto;
  font-style: normal;
  font-weight: 500;
  font-size: 20px;
  line-height: 22px;
  color: #000000;
  margin: 10px 0 20px 10px;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
input[type="number"] {
  -moz-appearance: textfield;
}
</style>
